nuo.callback.notification = {
    dropdownMenu : function(t) {
        if (!t.hasClass('first')) {
            t.addClass('first');
            $.get(_config.basePath + 'notification/ajax/menu/notification', '', function(html) {
                $('#uiNotificationContent').html(html);
            });
        }
    }
}
nuo.callback.link = {
    parse : function(input, params) {
        $.post(_config.basePath + 'link/ajax/preview', params, function(json) {
            var e = $('.uiActivityFeedPostAttachmentLink');
            e.html(json.html).show();
        }, 'json');
    },
    parseCallback : function(json) {

    }
}

nuo.callback.request = {
    dropdownMenu : function(t) {
        if (!t.hasClass('first')) {
            t.addClass('first');
            $.get(_config.basePath + 'request/ajax/menu/request', '', function(html) {
                $('#uiRequestContent').html(html);
            });
        }
    }
}

nuo.callback.message = {
    dropdownMenu : function(t) {
        if (!t.hasClass('first')) {
            t.addClass('first');
            $.get(_config.basePath + 'message/ajax/menu/inbox', '', function(html) {
                $('#uiInboxContent').html(html);
            });
        }
    }
}

nuo.callback.form = {
    submit : function(t) {
        var act = t.attr('aria-act'), form = t.closest('form');
        if (!nuo.isEmpty(act)) {
            form.find('.uiHiddenAct').val(act);
        }
        nuo.async(form);
    }
}

nuo.callback.friend = {
    request : function(t) {
        $.getJSON(_config.basePath + 'friend/ajax/request', {
            'data-id' : t.attr('data-id')
        }, function(json) {
            var id = json.html_id;
            var e = $('#' + id);
            e.find('.uiButtonText').html(json.html);
        });
    },
    confirm : function(t) {
        $.getJSON(_config.basePath + 'friend/ajax/confirm', {
            'data-id' : t.attr('data-id')
        }, function(json) {
            var id = json.html_id;
            var e = $('#' + id);
            e.html(json.html);
        });
    }
}

nuo.callback.activity = {
    like : function(t) {
        var data = nuo.getDataObj(t);
        $.post(_config.basePath + 'activity/ajax/like', data, this.likeCallback, 'json');
    },
    likeCallback : function(json) {
        console.log(json);
        // fire an event then 
        var id = '#' + json.html_id, dom = $(id);
        dom.find('.uiFeedLikeLinkPlh').html(json.html);
        dom.find('.uiFeedLikeMsgPlh').html(json.like_html);
        if (json.like_count == 0) {
            dom.find('.uiFeedLikeMsg').addClass('hidden');
        } else {
            dom.find('.uiFeedLikeMsg').removeClass('hidden');
        }
    },
    likeCommentCallback : function(json) {
        var cmt = $('#' + json.html_id);
        cmt.find('.uiLikeCommentButton').html(json.html);
        if (json.like_count == 0) {
            cmt.find('.uiCommentLikeText').addClass(' hidden');

        } else {
            cmt.find('.uiCommentLikeText').removeClass('hidden').html('&middot;  ' + json.like_html);
        }

    },
    focus : function(t) {
        t.closest('.feedEntry').find('.uiCommentTextArea').focus()
    },
    remove : function(t) {
        t.closest('.commentEntry').css({
            'opacity' : 0.7
        });
        $.getJSON(_config.basePath + 'comment/ajax/remove', {
            'data-id' : t.attr('data-id')
        }, this.removeCallback);
    },
    removeCallback : function(json) {
        var id = '#' + json.html_id;
        $(id).fadeOut();
    },
    addCallback : function(json) {
        var id = '#' + json.html_id, dom = $(id);
        dom.find('.commentCompose').before(json.html);
        dom.find('.uiMentionTypeahead').val('').trigger('changed').focus();
    }
}

nuo.callback.feed = {
    resetComposer : function() {
        $('.uiPostComposer .uiMentionTypeahead').val('').trigger('changed').focus();
    },
    addPostCallback : function(json) {
        var t = nuo.callback.feed;
        $('.uiActivityFeedItemList').prepend(json.html);
        t.resetComposer();
    }
}

nuo.callback.composer = {
    def : function(t) {
        t.closest('form').find('.uiActivityFeedPostAttachmentFragment').hide();
        t.closest('.uiList').find('.uiActive').removeClass('uiActive');
        t.addClass('uiActive');
        t.closest('form').find('.uiHiddenFeedType').val(t.attr('aria-feed-type'));
        t.closest('form').attr('action', t.attr('aria-action'));
    },
    setPrivacy : function(t, evt) {
        var p = $(t).closest('.uiToggleWrapper');
        var data = $(t).attr('aria-data').split('.');
        p.find('.uiDynamicText').text(t.text());
        p.find('.uiDynamicValue').val(data[0]);
        var form = t.closest('form');
        $.post(_config.basePath + 'privacy/ajax/simplesave', {
            'privacy' : data[0]
        });
        $(document).trigger('click');
    },
    post : function(t) {
        this.def(t);
    },
    photo : function(t) {
        this.def(t);
        t.closest('form').find('.uiActivityFeedPostAttachmentPhoto').show();
    },
    video : function(t) {
        this.def(t);
        t.closest('form').find('.uiActivityFeedPostAttachmentVideo').show();
    }
}

nuo.mceEditor = function(e) {
    tinymce.init({
        selector : "textarea",
        elements : [e],
        plugins : ["advlist autolink lists link image charmap print preview anchor", "searchreplace visualblocks code fullscreen", "insertdatetime media table contextmenu paste"],
        toolbar : "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
    });
}
